package com.cskaoyan.controller.wx;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.Comment;
import com.cskaoyan.bean.CommentCount;
import com.cskaoyan.bean.CommentData;
import com.cskaoyan.bean.bo.CommentBO;
import com.cskaoyan.bean.topic.TopicCommentPostBO;
import com.cskaoyan.service.wx.WxCommentService;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author pengyehua
 * @date 2020/12/9 15:27
 */
@RestController
@RequestMapping("wx/comment")
public class WxCommentController {

    @Autowired
    WxCommentService wxCommentService;

    /**
     * 查询评论数量
     * @param valueId
     * @param type
     * @return
     */
    @RequestMapping("count")
    public BaseRespVo count(int valueId,byte type){
        CommentCount commentCount = wxCommentService.queryCommentCount(valueId,type);
        return BaseRespVo.ok(commentCount);
    }

    /**
     * 查询所有评论
     * @param commentBO
     * @return
     */
    @RequestMapping("list")
    public BaseRespVo list(CommentBO commentBO){
        CommentData commentData = wxCommentService.queryComment(commentBO);
        return BaseRespVo.ok(commentData);
    }

    @RequestMapping("post")
    public BaseRespVo post(@RequestBody TopicCommentPostBO topicCommentPostBO){
        Integer userId = (Integer) SecurityUtils.getSubject().getSession().getAttribute("id");
        Comment comment = wxCommentService.insertComment(topicCommentPostBO, userId);
        return BaseRespVo.ok(comment);
    }
}
